home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / addpcx.zip / VGR.C < prev    next >
C/C++ Source or Header  |  1988-06-21  |  2KB  |  119 lines

  1. /*    VGR.c    -  Routines that access the BIOS or are otherwise
  2.                 related to video, but not board specific.
  3. */
  4.  
  5.  
  6. #include "lib.h"
  7. #include "vgr.h"
  8.  
  9.  
  10. /*    VGR_GET_BOARD
  11.  
  12.     Partly by Dan Laurence, 
  13.     from MicroEMACS, IBMPC.C, page 5 
  14.     Hercules test by Larry Fogg, 
  15.     from MicroC, jan-feb '88, page 26.
  16.  
  17.     It's difficult for me to test this...
  18.     My ATI EGA Wonder is basically either a
  19.     HERC or EGA board... Besides that, there's
  20.     no perfect algorithm available for this 
  21.     problem...
  22. */
  23.  
  24. int vgr_get_board()
  25. {
  26.     int i;
  27.     REGS r;
  28.  
  29.     /* Check for MONO */
  30.     sysint( 0x11, &r, &r );
  31.     if ( ( (r.ax >> 4) & 0x03 ) == 0x03 )
  32.     {  for ( i=0; i < 0x1000; i++ )
  33.           if ( inportb( 0x3ba ) & 0x80 )
  34.              return TYPE_HERC;
  35.        return TYPE_MDA;
  36.     };
  37.  
  38.     /* Check for EGA
  39.     */
  40.     r.ax = 0x1200;
  41.     r.bx = 0xff10;
  42.     sysint( 0x10, &r, &r );
  43.     if ( !(r.bx & (~0x0103)) )    /* might be EGA...   */
  44.        return TYPE_EGA;
  45.     else return TYPE_CGA; /* should be CGA, but...  */
  46. }
  47.  
  48.  
  49. int vgr_mode( mode )
  50. unsigned char mode;
  51. {
  52.     REGS r;
  53.  
  54.     r.ax = mode;
  55.     sysint( 0x10, &r, &r );
  56.  
  57.     return OK;
  58. }
  59.  
  60.  
  61. /*    adapted from jan/feb microcornucopia, page 85
  62.     by Gary Entsminger. Gary's ref: Bresenham's algorithm,
  63.     from Advanced Turbo C by Herbert Schildt.
  64. */
  65.  
  66. void vgr_line( x1, y1, x2, y2, color )
  67. int x1, x2, y1, y2, color;
  68. {
  69.     int t, distance, xerr, yerr, dx, dy, ix, iy;
  70.  
  71.     ix = (dx = x2-x1) < 0 ? (dx = -dx, -1) : !!dx;
  72.     iy = (dy = y2-y1) < 0 ? (dy = -dy, -1) : !!dy;
  73.  
  74.     distance = dx > dy ? dx : dy;
  75.  
  76.     xerr = yerr = 0;
  77.     for ( t = -2; t < distance; t++ )
  78.     {  VGR_SET( x1, y1, color );
  79.  
  80.        xerr += dx;
  81.        yerr += dy;
  82.  
  83.        if ( xerr > distance )
  84.        {  xerr -= distance;
  85.           x1   += ix;
  86.        };
  87.  
  88.        if ( yerr > distance )
  89.        {  yerr -= distance;
  90.           y1   += iy;
  91.        };
  92.     };
  93. }
  94.  
  95.  
  96. void vgr_rectangle( x1, y1, x2, y2, color )
  97. int x1, x2, y1, y2, color;
  98. {
  99.     vgr_line( x1, y1, x1, y2, color );
  100.     vgr_line( x1, y2, x2, y2, color );
  101.     vgr_line( x2, y2, x2, y1, color );
  102.     vgr_line( x2, y1, x1, y1, color );
  103. }
  104.  
  105.  
  106. void vgr_point( x2, y2, color )
  107. int x2, y2, color;
  108. {
  109.     static int x1=0, y1=0;
  110.  
  111.     if ( color != -1 )
  112.        vgr_line( x1, y1, x2, y2, color );
  113.  
  114.     x1 = x2;
  115.     y1 = y2;
  116.     return;
  117. }
  118.  
  119.